package com.ruoyi.contact.controller;

import com.ruoyi.contact.service.IContactReportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
public class ContactRportController {

    private String prefix="contact/report";

    @Autowired
    private IContactReportService contactReportService;

    @RequiresPermissions("contact:report:view")
    @GetMapping("/contact/toReport")
    public String toReport(ModelMap modelMap){
        List<Map<String, Integer>> countByCategory = contactReportService.selectContactCountByCategory();
        modelMap.put("datacountBycategory", countByCategory);
        return"contact/report/report";
    }

    @RequiresPermissions("contact:report:view")
    @GetMapping("/contact/drawPie")
    public String drawPie(ModelMap modelMap){
        List<Map<String, Integer>> countByCategory = contactReportService.selectContactCountByCategory();
        modelMap.put("dataCountByCategory",countByCategory);
        return "contact/report/pie";
    }
    @ExceptionHandler(Exception.class)
    public String handleError(Model model, Exception ex) {
        model.addAttribute("error", ex.getMessage());
        return "error"; // 创建一个简单的error.html页面显示错误信息
    }
    @RequiresPermissions("contact:report:view")
    @GetMapping("/contact/drawBar")
    public String toReport1(ModelMap modelMap){
        List<Map<String, Integer>> countByCategory = contactReportService.selectContactCountByCategory();
        modelMap.put("dataCountByCategory",countByCategory);
        return "contact/report/bar";
    }
}
